<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

/**
 * App\Good
 *
 * @property int $id 商品主键
 * @property string|null $goods_name 商品名称
 * @property string|null $goods_thumbnail 商品缩略图
 * @property float|null $cost_price
 * @property float|null $repeat_price 复购价格
 * @property int|null $stock 库存
 * @property string|null $detail 商品详情
 * @property string|null $slide 轮播图
 * @property int|null $sale_num 已销售商品数量，以此为目标判断商品是否热卖
 * @property int|null $is_ recommend 是否推荐
 * @property string|null $sale_start_time 销售开始时间
 * @property string|null $sale_end_time  销售结束时间
 * @property \Carbon\Carbon|null $created_at 创建
 * @property \Carbon\Carbon|null $updated_at
 * @property int|null $is_sale 0 上架 1 下架
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereCostPrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereDetail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereGoodsName($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereGoodsThumbnail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereIsRecommend($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereIsSale($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereRepeatPrice($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereSaleEndTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereSaleNum($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereSaleStartTime($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereSlide($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereStock($value)
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereUpdatedAt($value)
 * @mixin \Eloquent
 * @property int|null $is_recommend 是否推荐
 * @property string|null $send_time 发货时间
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereSendTime($value)
 * @property int|null $send_day 预计几天后发货
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Good whereSendDay($value)
 */
class Good extends Model
{
    public function setSlideAttribute($pictures)
    {

     if (is_array($pictures)) {
            $this->attributes['slide'] = json_encode($pictures);
        }
    }
    public function getSlideAttribute($pictures){

        return  json_decode($pictures, true);
    }

    public function getGoodsThumbnailAttribute($value){
        return config('filesystems.disks')[config('admin.upload.disk')]['url'].'/'.$value;
    }
    public static function getSelectOptions()
    {
        $options = \DB::table('goods')->select('id','goods_name as text')->get();
        $selectOption = [];
        foreach ($options as $option){
            $selectOption[$option->id] = $option->text;
        }
        return $selectOption;
    }
}
